package com.gitee.java17demo.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(){
		return "Hello, Java and Spring Boot";
	}

	@PostMapping("/user")
	public String createUser(@RequestBody CreateUserRequest request)
	{
		if (request.getEmail() == null || request.getEmail().isEmpty()){
			return "Email不能为空";
		}

		if (request.getPassword() == null || request.getPassword().isEmpty()){
			return "Password不能为空";
		}
		return "create user : email: %s, password : %s"
				.formatted(
						request.getEmail(),
						request.getPassword()
				);
	}

	class CreateUserRequest{
		private  String email;
		private String password;

		public String getPassword() {
			return password;
		}

		public void setPassword(String password) {
			this.password = password;
		}

		public String getEmail() {
			return email;
		}

		public void setEmail(String email) {
			this.email = email;
		}
	}
}
